#include "MyCoroutine.h"

#include <iostream>

template <typename T>
MyCoroutine<T>::MyCoroutine(CoroHandler h) : _handle(h)
{
    std::cout << "MyCoroutine" << std::endl;
}

template <typename T>
MyCoroutine<T>::~MyCoroutine()
{
    std::cout << "~MyCoroutine" << std::endl;
    if (_handle)
    {
        _handle.destroy();
    }
}

template <typename T>
bool MyCoroutine<T>::Resume()
{ 
    if (!_handle.done())
    {
        _handle.resume();
        return true;
    }

    std::cout << "coroutine has done" << std::endl;
    return false;
}

template <typename T>
bool MyCoroutine<T>::Done() 
{ 
    return _handle.done();
}

template <typename T>
T MyCoroutine<T>::GetValue() 
{ 
    return _handle.promise().value;
}

// 显式实例化模板
template class MyCoroutine<int>;
template class MyCoroutine<int64_t>;